package client;

import tools.*;
import java.io.IOException;
import java.util.HashMap;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class CardImages
{
	HashMap<String,Icon> cardImages = new HashMap<String,Icon>();

	public CardImages()
	{
		Deck d = new Deck();
		for(Card c: d.deck)
			loadImage(c.getRankSuit());
		loadImage("face_down");
		loadImage("no_card");
	}
	
	public Icon getIcon(String s)
	{
		return (Icon)cardImages.get(s);
	}
	
	public Image getImage(String s)
	{
		BufferedImage img = getBufferedImage(s);
		return img;
	}
	
	public BufferedImage getBufferedImage(String s)
	{
		BufferedImage img = null;
		try 
		{
			img = ImageIO.read(CardImages.class.getResourceAsStream("images/" + s + ".png"));
		}
		catch (IOException e) 
		{
		    e.printStackTrace();
		}
		return img;
	}
	
	private void loadImage(String s) 
	{
		BufferedImage img = getBufferedImage(s);
		if (img != null)
		{
			int hight = 60;
			Icon icon = new ImageIcon(img.getScaledInstance(hight, (int)(hight*1.25), Image.SCALE_SMOOTH));
			cardImages.put(s, icon);
		}
	}
}
